
#include "Common/TableDataEx/TeamCfg.h"
#include "Common/TableData/TeamTeamCfg.h"

TeamCfg::TeamCfg()
{
	m_teamType.clear();
}

TeamCfg::~TeamCfg()
{

}


bool TeamCfg::Init()
{
	const TeamTeamCfgMap *pCfgMap = g_GetTeamTeamCfgTable()->GetTeamTeamCfgMap();
	if (nullptr != pCfgMap)
	{
		TeamTeamCfgMap::const_iterator iter = pCfgMap->begin();
		for (; iter != pCfgMap->end(); ++iter)
		{
			const TeamTeamCfgInfo &info = iter->second;
			uint32_t type = info.FObjectNameID;
			uint32_t subType = info.SObjectNameID;
			uint32_t teamObjectId = info.TeamObjectID;
			OEDER_MAP_UINT32_ORDER_MAP_UINT32_UINT32::iterator typeIter = m_teamType.find(type);
			if (typeIter == m_teamType.end())
			{
				ORDER_MAP_UINT32_UINT32 subTypeMap;
				subTypeMap.insert(std::make_pair(subType, teamObjectId));
				m_teamType.insert(std::make_pair(type, subTypeMap));
			}
			else
			{
				ORDER_MAP_UINT32_UINT32::iterator subTypeIter = typeIter->second.find(subType);
				if (subTypeIter == typeIter->second.end())
				{
					typeIter->second.insert(std::make_pair(subType, teamObjectId));
				}
			}
		}
	}

	return true;
}

bool TeamCfg::UnInit()
{
	m_teamType.clear();

	return true;
}

const TeamTeamCfgInfo* TeamCfg::GetTeamTeamCfgInfo(uint32_t type, uint32_t subType)
{
	OEDER_MAP_UINT32_ORDER_MAP_UINT32_UINT32::iterator typeIter = m_teamType.find(type);
	if (typeIter == m_teamType.end())
	{
		return nullptr;
	}

	ORDER_MAP_UINT32_UINT32::iterator subTypeIter = typeIter->second.find(subType);
	if (subTypeIter == typeIter->second.end())
	{
		return nullptr;
	}

	return g_GetTeamTeamCfgTable()->GetTeamTeamCfgInfo(subTypeIter->second);
}

const TeamTeamCfgInfo* TeamCfg::GetTeamInitCfgInfo()
{
	return GetTeamTeamCfgInfo(0, 0);
}

uint32_t TeamCfg::GetTeamObject(uint32_t type, uint32_t subType)
{
	OEDER_MAP_UINT32_ORDER_MAP_UINT32_UINT32::iterator typeIter = m_teamType.find(type);
	if (typeIter == m_teamType.end())
	{
		return 0;
	}

	ORDER_MAP_UINT32_UINT32::iterator subTypeIter = typeIter->second.find(subType);
	if (subTypeIter == typeIter->second.end())
	{
		return 0;
	}

	return subTypeIter->second;
}